<?php

namespace App\Models\Casts;

use Illuminate\Database\Eloquent\Model;
use Cache;


class Skill extends Model
{
    protected $guarded = [];

    /**
     * 一个技能下有多个系列
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function series()
    {
        return $this->hasMany('App\Models\Casts\Series');
    }

    /**
     * 获取技能数据
     * @return mixed
     */
    static function get_skills()
    {
        $skills = Cache::rememberForever('casts_skills', function () {
            return self::orderBy('sort_order')->get();
        });

        return $skills;
    }

    /**
     * 检查是否有系列
     */
    static function check_series($id)
    {
        $skill = self::with('series')->find($id);
        if ($skill->series->isEmpty()) {
            return true;
        }
        return false;
    }

    //清除缓存
    static function clear()
    {
        Cache::forget('casts_skills');
    }
}
